package com.hockeo.client.model;

/**
 * Represents the login status of the currently connected user.
 *
 * @version $Id$
 * @author jjanke
 */
@SuppressWarnings( "serial" )
public class LoginStatus extends JSData
{
  public static final String PARAM_USER  = "js_user";
  public static final String PARAM_ADMIN = "js_admin";
  public static final String PARAM_URL   = "js_url";

  public LoginStatus()
  {
    set( PARAM_ID, "loginStatus" );
  }

  /**
   * Creates a new login status object.
   *
   * @param strUser the name of the connected user or <code>null</code> if nobody is
   *          connected
   * @param fAdmin indicates whether the connected user is an admin or not
   * @param strUrl the URL to be used for login/logout (which one it is depends on whether
   *          there is a logged in user or not)
   */
  public LoginStatus( String strUser, Boolean fAdmin, String strUrl )
  {
    if ( strUser != null )
    {
      set( PARAM_USER, strUser );
      set( PARAM_ADMIN, fAdmin );
    }

    set( PARAM_URL, strUrl );
  }

  /**
   * Returns the name of the connected user or <code>null</code> if nobody is currently
   * connected.
   */
  public String getUserName()
  {
    return getString( PARAM_USER );
  }

  /**
   * Indicates whether the connected user is an administrator or not.
   */
  public boolean isAdmin()
  {
    return getBoolean( PARAM_ADMIN );
  }

  /**
   * Returns the login/logout URL. Which one it is depends on whether a user is currently
   * connected or not.
   */
  public String getUrl()
  {
    return getString( PARAM_URL );
  }
}
